<template>
  <NvCrud :option :data @refresh="handleRefresh">
    <template #toolbar_pre>
      <NGradientText type="info">
        toolbar_pre
      </NGradientText>
    </template>
    <template #toolbar>
      <NGradientText type="danger">
        toolbar
      </NGradientText>
    </template>
  </NvCrud>
</template>

<script setup lang="ts">
import type { NvCrudOption } from 'nv-crud'
import { NGradientText } from 'naive-ui'
import { NvCrud } from 'nv-crud'

const data = Array.from({ length: 3 }, (_, i) => ({
  id: i + 1,
  name: `name${i + 1}`,
  sex: i % 2 === 0 ? '男' : '女',
  age: i + 1,
}))

const option: NvCrudOption = {
  rowActions: false,
  actionbar: false,
  fields: {
    name: { title: '姓名' },
    sex: { title: '性别' },
    age: { title: '年龄' },
  },
}

function handleRefresh(done: () => void) {
  setTimeout(done, 1000)
}
</script>
